import { goods } from "../../api";
const MUTATION_TYPES = {
  GOODS_LIST: "GOODS_LIST",
  GOODS_SIZE: "GOODS_SIZE"
};

const state = {
  goodsList: [],
  totalGoodsSize: 0
};
const getters = {};

const mutations = {
  [MUTATION_TYPES.GOODS_LIST](state, goodsList) {
    state.goodsList = goodsList;
  },
  [MUTATION_TYPES.GOODS_SIZE](state, totalGoodsSize) {
    state.totalGoodsSize = totalGoodsSize;
  }
};

const actions = {
  async search({ commit }, filter = {}) {
    let response = await goods.search(filter);
    if (response?.code === 0) {
      commit(MUTATION_TYPES.GOODS_LIST, response.data?.records);
      commit(MUTATION_TYPES.GOODS_SIZE, response.data?.total);
    }
  }
};

export default {
  namespaced: true,
  state,
  getters,
  mutations,
  actions
};
